<template>
  <div class="box">
    <img :src="url" alt="卡哇伊" />
    <p :style="{ backgroundColor: colorStr }" @click.once="btn">
      {{ name }}
    </p>
  </div>
</template>

<script>
export default {
  props: ["name", "url"],
  data() {
    return {
      colorStr: "",
      dogName: "",
    };
  },
  methods: {
    btn() {
      // 点击随机背景色
      this.colorStr = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(
        Math.random() * 256
      )},${Math.floor(Math.random() * 256)})`;
      //   通过子传父触发事件
      this.$emit("like");
    },
  },
};
</script>

<style scoped>
.box {
  width: 33%;
  border: 1px solid black;
  text-align: center;
  box-sizing: border-box;
}
img {
  width: 100%;
  height: 300px;
}
</style>